package c.j.a.d.a;

import android.app.NotificationChannel;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import c.j.a.c.l;
import c.j.a.c.y.a.i;
import c.j.a.d.b.n.c0;
import java.io.File;
import java.text.DecimalFormat;
import java.util.Objects;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: AppDownloadUtils */
public class h {
    public static NotificationChannel a;

    /* compiled from: AppDownloadUtils */
    public static class a implements Runnable {
        public final /* synthetic */ Context a;
        public final /* synthetic */ int b;
        public final /* synthetic */ boolean c;
        public final /* synthetic */ com.ss.android.socialbase.downloader.g.c d;
        public final /* synthetic */ File e;

        public a(Context context, int i, boolean z, com.ss.android.socialbase.downloader.g.c cVar, File file) {
            this.a = context;
            this.b = i;
            this.c = z;
            this.d = cVar;
            this.e = file;
        }

        /* JADX WARNING: Removed duplicated region for block: B:101:0x020e  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:258:0x04b2  */
        /* JADX WARNING: Removed duplicated region for block: B:257:0x04aa  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:261:0x04c3  */
        /* JADX WARNING: Removed duplicated region for block: B:264:0x04dc  */
        /* JADX WARNING: Removed duplicated region for block: B:149:0x02bc  */
        /* JADX WARNING: Removed duplicated region for block: B:145:0x02b1  */
        /* JADX WARNING: Removed duplicated region for block: B:76:0x016e A:{SKIP} */
        /* JADX WARNING: Missing block: B:11:0x0049, code skipped:
            if (r9 == null) goto L_0x0057;
     */
        /* JADX WARNING: Missing block: B:142:0x02ac, code skipped:
            if (r3 != false) goto L_0x02ae;
     */
        /* JADX WARNING: Missing block: B:279:0x0548, code skipped:
            if (r11 != 0) goto L_0x0218;
     */
        public void run() {
            /*
            r19 = this;
            r1 = r19;
            r2 = r1.a;
            r3 = r1.b;
            r4 = r1.c;
            r5 = r1.d;
            r6 = r1.e;
            r7 = android.os.Build.VERSION.SDK_INT;
            r0 = r6.getPath();
            r8 = android.os.Environment.getDataDirectory();
            r8 = r8.getAbsolutePath();
            r0 = r0.startsWith(r8);
            r8 = 0;
            if (r0 == 0) goto L_0x0057;
        L_0x0021:
            r0 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0044 }
            r0.<init>();	 Catch:{ all -> 0x0044 }
            r9 = "chmod 555 ";
            r0.append(r9);	 Catch:{ all -> 0x0044 }
            r9 = r6.getAbsolutePath();	 Catch:{ all -> 0x0044 }
            r0.append(r9);	 Catch:{ all -> 0x0044 }
            r0 = r0.toString();	 Catch:{ all -> 0x0044 }
            r9 = java.lang.Runtime.getRuntime();	 Catch:{ all -> 0x0044 }
            r9 = r9.exec(r0);	 Catch:{ all -> 0x0044 }
            r9.waitFor();	 Catch:{ all -> 0x0042 }
            goto L_0x004b;
        L_0x0042:
            r0 = move-exception;
            goto L_0x0046;
        L_0x0044:
            r0 = move-exception;
            r9 = r8;
        L_0x0046:
            r0.printStackTrace();	 Catch:{ all -> 0x004f }
            if (r9 == 0) goto L_0x0057;
        L_0x004b:
            r9.destroy();
            goto L_0x0057;
        L_0x004f:
            r0 = move-exception;
            r2 = r0;
            if (r9 == 0) goto L_0x0056;
        L_0x0053:
            r9.destroy();
        L_0x0056:
            throw r2;
        L_0x0057:
            r2.getPackageManager();
            r0 = c.j.a.d.a.h.a();	 Catch:{ all -> 0x006d }
            r9 = c.j.a.c.y.a.i.c(r2, r6, r0);	 Catch:{ all -> 0x006d }
            if (r9 == 0) goto L_0x006b;
        L_0x0064:
            r0 = r9.packageName;	 Catch:{ all -> 0x0069 }
            r5.x = r0;	 Catch:{ all -> 0x0069 }
            goto L_0x006b;
        L_0x0069:
            r0 = move-exception;
            goto L_0x006f;
        L_0x006b:
            r0 = r8;
            goto L_0x006f;
        L_0x006d:
            r0 = move-exception;
            r9 = r8;
        L_0x006f:
            r10 = c.j.a.d.a.i.j();
            r10 = r10.c;
            if (r10 == 0) goto L_0x0097;
        L_0x0077:
            if (r9 != 0) goto L_0x008c;
        L_0x0079:
            r10 = new com.ss.android.socialbase.downloader.e.a;
            r11 = 2001; // 0x7d1 float:2.804E-42 double:9.886E-321;
            r10.m4678init(r11, r0);
            r0 = c.j.a.d.a.i.j();
            r0 = r0.c;
            r11 = r10.a;
            r0.a(r5, r10, r11);
            goto L_0x0097;
        L_0x008c:
            r0 = c.j.a.d.a.i.j();
            r0 = r0.c;
            r10 = 11;
            r0.a(r5, r8, r10);
        L_0x0097:
            r10 = 1;
            r11 = 0;
            if (r9 == 0) goto L_0x0168;
        L_0x009b:
            r0 = r9.packageName;
            r12 = r5.w;
            r0 = r0.equals(r12);
            if (r0 != 0) goto L_0x0168;
        L_0x00a5:
            r0 = c.j.a.d.a.i.j();
            r0 = r0.b;
            if (r0 == 0) goto L_0x0144;
        L_0x00ad:
            r12 = r5.g0();
            r13 = r9.packageName;
            r14 = r0.a;
            r15 = "forbid_invalidte_download_file_install";
            if (r14 != 0) goto L_0x00bb;
        L_0x00b9:
            goto L_0x012b;
        L_0x00bb:
            r14 = c.j.a.d.b.e.i.a(r14);
            r12 = r14.k(r12);
            if (r12 == 0) goto L_0x012b;
        L_0x00c5:
            r14 = r12.o0();
            r8 = -3;
            if (r14 == r8) goto L_0x00cd;
        L_0x00cc:
            goto L_0x012b;
        L_0x00cd:
            r12.w = r13;
            r8 = c.j.a.c.g.h.a();
            r13 = r0.a;
            java.util.Objects.requireNonNull(r8);
            r0 = c.j.a.c.g.y.t();
            r0 = r0.optInt(r15, r11);
            if (r0 != r10) goto L_0x00e4;
        L_0x00e2:
            r0 = 1;
            goto L_0x00e5;
        L_0x00e4:
            r0 = 0;
        L_0x00e5:
            if (r0 != 0) goto L_0x00e8;
        L_0x00e7:
            goto L_0x012b;
        L_0x00e8:
            r0 = new java.io.File;	 Catch:{ Exception -> 0x0101 }
            r14 = r12.e;	 Catch:{ Exception -> 0x0101 }
            r10 = r12.b;	 Catch:{ Exception -> 0x0101 }
            r0.<init>(r14, r10);	 Catch:{ Exception -> 0x0101 }
            r10 = r0.isFile();	 Catch:{ Exception -> 0x0101 }
            if (r10 == 0) goto L_0x0105;
        L_0x00f7:
            r10 = r0.exists();	 Catch:{ Exception -> 0x0101 }
            if (r10 == 0) goto L_0x0105;
        L_0x00fd:
            r0.delete();	 Catch:{ Exception -> 0x0101 }
            goto L_0x0105;
        L_0x0101:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x0105:
            r0 = r8.a;
            if (r0 != 0) goto L_0x0114;
        L_0x0109:
            r0 = new android.os.Handler;
            r10 = android.os.Looper.getMainLooper();
            r0.<init>(r10);
            r8.a = r0;
        L_0x0114:
            r0 = r12.d;
            r10 = c.j.a.d.b.e.i.a(r13);
            r12 = r12.g0();
            r10.m(r12);
            r10 = r8.a;
            r12 = new c.j.a.c.g$f;
            r12.m2262init(r8, r0);
            r10.post(r12);
        L_0x012b:
            r0 = c.j.a.c.g.h.a();
            java.util.Objects.requireNonNull(r0);
            r0 = c.j.a.c.g.y.t();
            r0 = r0.optInt(r15, r11);
            r8 = 1;
            if (r0 != r8) goto L_0x013f;
        L_0x013d:
            r0 = 1;
            goto L_0x0140;
        L_0x013f:
            r0 = 0;
        L_0x0140:
            if (r0 == 0) goto L_0x0144;
        L_0x0142:
            r0 = 1;
            goto L_0x0169;
        L_0x0144:
            r0 = c.j.a.d.b.e.i.a(r2);
            r8 = r5.g0();
            r0 = r0.l(r8);
            if (r0 == 0) goto L_0x0168;
        L_0x0152:
            r8 = 8;
            r10 = r9.packageName;
            r12 = "";
            r0.J(r8, r5, r10, r12);
            r0 = c.j.a.d.a.i.j();
            r0 = r0.a;
            r8 = r0 instanceof c.j.a.d.a.h.b;
            if (r8 == 0) goto L_0x0168;
        L_0x0165:
            java.util.Objects.requireNonNull(r0);
        L_0x0168:
            r0 = 0;
        L_0x0169:
            r8 = 2;
            if (r0 == 0) goto L_0x016e;
        L_0x016c:
            goto L_0x02b6;
        L_0x016e:
            if (r9 == 0) goto L_0x0196;
        L_0x0170:
            r0 = r5.g0();
            r0 = c.j.a.d.b.l.a.d(r0);
            r10 = "install_callback_error";
            r0 = r0.k(r10, r11);
            if (r0 == 0) goto L_0x0196;
        L_0x0180:
            r0 = r5.Y();
            r10 = r9.packageName;
            r12 = "extra_apk_package_name";
            r0.putString(r12, r10);
            r0 = r5.Y();
            r10 = r9.versionCode;
            r12 = "extra_apk_version_code";
            r0.putInt(r12, r10);
        L_0x0196:
            r10 = 1;
            r12 = new int[r10];
            r0 = c.j.a.d.a.h.n(r2, r5, r9);
            if (r0 == 0) goto L_0x01ac;
        L_0x019f:
            r0 = r9.packageName;
            r3 = r2.getPackageManager();
            r0 = r3.getLaunchIntentForPackage(r0);
        L_0x01a9:
            r3 = r0;
            goto L_0x02af;
        L_0x01ac:
            if (r4 != 0) goto L_0x021b;
        L_0x01ae:
            r0 = c.j.a.d.b.l.a.d(r3);
            r3 = "back_miui_silent_install";
            r0 = r0.b(r3, r10);
            if (r0 != r10) goto L_0x01bb;
        L_0x01ba:
            goto L_0x020b;
        L_0x01bb:
            r0 = c.j.a.d.b.n.d0.j();
            if (r0 != 0) goto L_0x01c8;
        L_0x01c1:
            r0 = c.j.a.d.b.n.d0.k();
            if (r0 != 0) goto L_0x01c8;
        L_0x01c7:
            goto L_0x020b;
        L_0x01c8:
            r0 = "com.miui.securitycore";
            r3 = "com.miui.enterprise.service.EntInstallService";
            r9 = c.j.a.c.y.a.i.q(r2, r0, r3);
            if (r9 == 0) goto L_0x020b;
        L_0x01d2:
            r9 = new android.content.Intent;
            r9.<init>();
            r10 = new android.content.ComponentName;
            r10.<init>(r0, r3);
            r9.setComponent(r10);
            r3 = new android.os.Bundle;
            r3.<init>();
            r10 = "userId";
            r3.putInt(r10, r11);
            r10 = 256; // 0x100 float:3.59E-43 double:1.265E-321;
            r13 = "flag";
            r3.putInt(r13, r10);
            r10 = r6.getPath();
            r13 = "apkPath";
            r3.putString(r13, r10);
            r10 = "installerPkg";
            r3.putString(r10, r0);
            r9.putExtras(r3);
            r2.startService(r9);	 Catch:{ Exception -> 0x0206 }
            r0 = 1;
            goto L_0x020c;
        L_0x0206:
            r0 = move-exception;
            r3 = r0;
            r3.printStackTrace();
        L_0x020b:
            r0 = 0;
        L_0x020c:
            if (r0 == 0) goto L_0x021b;
        L_0x020e:
            r0 = r5.Y();
            r2 = "extra_silent_install_succeed";
            r3 = 1;
            r0.putBoolean(r2, r3);
        L_0x0218:
            r10 = 1;
            goto L_0x0550;
        L_0x021b:
            r0 = c.j.a.d.b.e.i.a(r2);
            r3 = r5.g0();
            java.util.Objects.requireNonNull(r0);
            r0 = c.j.a.d.b.e.d.b();
            r0 = r0.h(r3);
            if (r0 != 0) goto L_0x0232;
        L_0x0230:
            r0 = 0;
            goto L_0x0236;
        L_0x0232:
            r0 = r0.w(r3);
        L_0x0236:
            r3 = c.j.a.d.a.i.j();
            r3 = r3.e;
            r5.g0();
            if (r0 == 0) goto L_0x0254;
        L_0x0241:
            r9 = r6.getAbsolutePath();	 Catch:{ all -> 0x025b }
            r0 = (c.j.a.d.b.n.o) r0;	 Catch:{ all -> 0x025b }
            r0 = r0.a;	 Catch:{ RemoteException -> 0x024f }
            r0 = r0.a(r3, r9);	 Catch:{ RemoteException -> 0x024f }
            r9 = r0;
            goto L_0x025c;
        L_0x024f:
            r0 = move-exception;
            r0.printStackTrace();	 Catch:{ all -> 0x025b }
            goto L_0x025b;
        L_0x0254:
            r0 = c.j.a.d.a.i.j();
            java.util.Objects.requireNonNull(r0);
        L_0x025b:
            r9 = 0;
        L_0x025c:
            r10 = 24;
            if (r9 != 0) goto L_0x0276;
        L_0x0260:
            if (r7 < r10) goto L_0x026d;
        L_0x0262:
            r0 = android.text.TextUtils.isEmpty(r3);	 Catch:{ all -> 0x0272 }
            if (r0 != 0) goto L_0x026d;
        L_0x0268:
            r9 = androidx.core.content.FileProvider.getUriForFile(r2, r3, r6);	 Catch:{ all -> 0x0272 }
            goto L_0x0276;
        L_0x026d:
            r9 = android.net.Uri.fromFile(r6);	 Catch:{ all -> 0x0272 }
            goto L_0x0276;
        L_0x0272:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x0276:
            if (r9 != 0) goto L_0x0279;
        L_0x0278:
            goto L_0x02ae;
        L_0x0279:
            r0 = new android.content.Intent;
            r3 = "android.intent.action.VIEW";
            r0.<init>(r3);
            if (r7 < r10) goto L_0x0286;
        L_0x0282:
            r3 = 1;
            r0.addFlags(r3);
        L_0x0286:
            r3 = "application/vnd.android.package-archive";
            r0.setDataAndType(r9, r3);
            r3 = c.j.a.d.a.i.j();
            r3 = r3.b;
            if (r3 == 0) goto L_0x0296;
        L_0x0293:
            r5.g0();
        L_0x0296:
            r3 = c.j.a.d.b.e.i.a(r2);
            r6 = r5.g0();
            r3 = r3.l(r6);
            if (r3 == 0) goto L_0x02a9;
        L_0x02a4:
            r3 = r3.a(r4);
            goto L_0x02aa;
        L_0x02a9:
            r3 = 0;
        L_0x02aa:
            r12[r11] = r3;
            if (r3 == 0) goto L_0x01a9;
        L_0x02ae:
            r3 = 0;
        L_0x02af:
            if (r3 != 0) goto L_0x02bc;
        L_0x02b1:
            r0 = r12[r11];
            r2 = 1;
            if (r0 != r2) goto L_0x02b9;
        L_0x02b6:
            r10 = 2;
            goto L_0x0550;
        L_0x02b9:
            r10 = 0;
            goto L_0x0550;
        L_0x02bc:
            r0 = 268435456; // 0x10000000 float:2.5243549E-29 double:1.32624737E-315;
            r3.addFlags(r0);
            r0 = r12[r11];
            if (r0 != 0) goto L_0x054c;
        L_0x02c5:
            r0 = c.j.a.d.a.g.a;
            r0 = r5.g0();
            r0 = c.j.a.d.b.l.a.d(r0);
            r6 = "anti_plans";
            r6 = r0.m(r6);
            if (r6 == 0) goto L_0x0548;
        L_0x02d7:
            r9 = r6.length();
            r10 = 0;
        L_0x02dc:
            if (r10 >= r9) goto L_0x0548;
        L_0x02de:
            r12 = r6.optJSONObject(r10);
            if (r12 == 0) goto L_0x0537;
        L_0x02e4:
            r0 = c.j.a.d.a.g.k(r12);
            if (r0 == 0) goto L_0x0537;
        L_0x02ea:
            r0 = c.j.a.d.a.g.n(r12);
            if (r0 == 0) goto L_0x0537;
        L_0x02f0:
            r13 = new c.j.a.d.a.d;
            r13.m2329init();
            r0 = "type";
            r0 = r12.optString(r0);
            r14 = android.text.TextUtils.isEmpty(r0);
            if (r14 != 0) goto L_0x052c;
        L_0x0301:
            r13.a = r0;
            r0.hashCode();
            r14 = r0.hashCode();
            r15 = 3;
            switch(r14) {
                case -2097307557: goto L_0x0330;
                case -1870668843: goto L_0x0325;
                case 778176993: goto L_0x031a;
                case 1146121817: goto L_0x030f;
                default: goto L_0x030e;
            };
        L_0x030e:
            goto L_0x033b;
        L_0x030f:
            r14 = "custom_save_path";
            r0 = r0.equals(r14);
            if (r0 != 0) goto L_0x0318;
        L_0x0317:
            goto L_0x033b;
        L_0x0318:
            r0 = 3;
            goto L_0x033c;
        L_0x031a:
            r14 = "jump_unknown_source";
            r0 = r0.equals(r14);
            if (r0 != 0) goto L_0x0323;
        L_0x0322:
            goto L_0x033b;
        L_0x0323:
            r0 = 2;
            goto L_0x033c;
        L_0x0325:
            r14 = "jump_file_manager_custom";
            r0 = r0.equals(r14);
            if (r0 != 0) goto L_0x032e;
        L_0x032d:
            goto L_0x033b;
        L_0x032e:
            r0 = 1;
            goto L_0x033c;
        L_0x0330:
            r14 = "jump_file_manager";
            r0 = r0.equals(r14);
            if (r0 != 0) goto L_0x0339;
        L_0x0338:
            goto L_0x033b;
        L_0x0339:
            r0 = 0;
            goto L_0x033c;
        L_0x033b:
            r0 = -1;
        L_0x033c:
            r14 = "anti_hijack_error_code";
            if (r0 == 0) goto L_0x03eb;
        L_0x0340:
            r11 = 1;
            if (r0 == r11) goto L_0x0388;
        L_0x0343:
            if (r0 == r8) goto L_0x0367;
        L_0x0345:
            if (r0 == r15) goto L_0x0349;
        L_0x0347:
            goto L_0x042f;
        L_0x0349:
            r0 = c.j.a.d.a.g.p(r12);
            r11 = r0.b;
            if (r11 == 0) goto L_0x0353;
        L_0x0351:
            goto L_0x03f3;
        L_0x0353:
            c.j.a.d.a.h.d(r2, r3);	 Catch:{ all -> 0x035b }
            r11 = 0;
            r13.b = r11;	 Catch:{ all -> 0x035b }
            goto L_0x03db;
        L_0x035b:
            r0 = move-exception;
            r11 = 4;
            r13.b = r11;
            r0 = r0.toString();
            r13.c = r0;
            goto L_0x04b9;
        L_0x0367:
            r0 = 26;
            if (r7 >= r0) goto L_0x0371;
        L_0x036b:
            r0 = c.j.a.d.b.n.d0.d();
            if (r0 == 0) goto L_0x04b9;
        L_0x0371:
            r0 = "enable_for_all";
            r11 = 0;
            r0 = r12.optInt(r0, r11);
            r11 = 1;
            if (r0 != r11) goto L_0x037d;
        L_0x037b:
            r0 = 1;
            goto L_0x037e;
        L_0x037d:
            r0 = 0;
        L_0x037e:
            if (r0 != 0) goto L_0x0382;
        L_0x0380:
            if (r4 == 0) goto L_0x04b9;
        L_0x0382:
            r0 = c.j.a.d.a.g.f(r2, r3, r12, r13);
            goto L_0x03f5;
        L_0x0388:
            r0 = c.j.a.d.a.g.o(r12);
            r11 = r0.b;
            if (r11 == 0) goto L_0x0391;
        L_0x0390:
            goto L_0x03f3;
        L_0x0391:
            r0 = r5.X();
            if (r0 != 0) goto L_0x03a5;
        L_0x0397:
            r5.M();
            r0 = r5.D0;
            r11 = -1;
            r0 = r0.optInt(r14, r11);
            r13.b = r0;
            goto L_0x04b9;
        L_0x03a5:
            r0 = r5.e;
            r11 = android.text.TextUtils.isEmpty(r0);
            if (r11 == 0) goto L_0x03af;
        L_0x03ad:
            goto L_0x042f;
        L_0x03af:
            r11 = "custom";
            r13.d = r11;
            r11 = c.j.a.d.a.c.d.a(r2, r11, r12, r5);
            if (r11 == 0) goto L_0x03e7;
        L_0x03b9:
            r12 = r11.a();
            if (r12 != 0) goto L_0x03c0;
        L_0x03bf:
            goto L_0x03e7;
        L_0x03c0:
            r11 = r11.b();
            if (r11 != 0) goto L_0x03c7;
        L_0x03c6:
            goto L_0x042f;
        L_0x03c7:
            r12 = new java.io.File;
            r12.<init>(r0);
            r0 = c.j.a.d.a.g.h(r12, r5);
            if (r0 == 0) goto L_0x03e2;
        L_0x03d2:
            r0 = c.j.a.d.a.g.m(r2, r11);
            if (r0 == 0) goto L_0x03dd;
        L_0x03d8:
            r11 = 0;
            r13.b = r11;
        L_0x03db:
            r0 = 1;
            goto L_0x03f5;
        L_0x03dd:
            r11 = 1;
            r13.b = r11;
            goto L_0x04b9;
        L_0x03e2:
            r11 = 6;
            r13.b = r11;
            goto L_0x04b9;
        L_0x03e7:
            r13.b = r15;
            goto L_0x04b9;
        L_0x03eb:
            r0 = c.j.a.d.a.g.o(r12);
            r11 = r0.b;
            if (r11 == 0) goto L_0x03ff;
        L_0x03f3:
            r13 = r0;
            r0 = 0;
        L_0x03f5:
            r16 = r4;
            r17 = r6;
            r18 = r7;
        L_0x03fb:
            r11 = 0;
        L_0x03fc:
            r4 = r0;
            goto L_0x04c1;
        L_0x03ff:
            r0 = r5.X();
            if (r0 != 0) goto L_0x0413;
        L_0x0405:
            r5.M();
            r0 = r5.D0;
            r11 = -1;
            r0 = r0.optInt(r14, r11);
            r13.b = r0;
            goto L_0x04b9;
        L_0x0413:
            r0 = "device_plans";
            r0 = r12.optString(r0);
            r13.e = r0;
            r11 = android.text.TextUtils.isEmpty(r0);
            if (r11 != 0) goto L_0x04b9;
        L_0x0421:
            r11 = ",";
            r11 = r0.split(r11);
            r0 = r5.e;
            r14 = android.text.TextUtils.isEmpty(r0);
            if (r14 == 0) goto L_0x0431;
        L_0x042f:
            goto L_0x04b9;
        L_0x0431:
            r14 = new java.io.File;
            r14.<init>(r0);
            r8 = new java.lang.StringBuilder;
            r8.<init>();
            r15 = r11.length;
            r16 = r4;
            r4 = 0;
        L_0x043f:
            if (r4 >= r15) goto L_0x04a2;
        L_0x0441:
            r17 = r6;
            r6 = r11[r4];
            r0 = c.j.a.d.a.c.d.a(r2, r6, r12, r5);
            if (r0 == 0) goto L_0x0493;
        L_0x044b:
            r0 = r0.b();
            if (r0 == 0) goto L_0x0484;
        L_0x0451:
            r18 = c.j.a.d.a.g.h(r14, r5);
            if (r18 == 0) goto L_0x0475;
        L_0x0457:
            r18 = r7;
            r7 = 0;
            c.j.a.d.a.g.g(r2, r0, r7);	 Catch:{ all -> 0x045f }
            r0 = 1;
            goto L_0x04a8;
        L_0x045f:
            r0 = move-exception;
            r7 = r0;
            r8.append(r6);
            r0 = " startActivity failed : ";
            r8.append(r0);
            r0 = c.j.a.d.a.g.b(r7);
            r8.append(r0);
            r7 = 1;
            c.j.a.d.a.g.d(r13, r7);
            goto L_0x0495;
        L_0x0475:
            r18 = r7;
            r7 = 6;
            c.j.a.d.a.g.d(r13, r7);
            r8.append(r6);
            r0 = " createDescFile failed! ";
            r8.append(r0);
            goto L_0x0495;
        L_0x0484:
            r18 = r7;
            r7 = 3;
            c.j.a.d.a.g.d(r13, r7);
            r8.append(r6);
            r0 = " resolveActivity failed! ";
            r8.append(r0);
            goto L_0x0496;
        L_0x0493:
            r18 = r7;
        L_0x0495:
            r7 = 3;
        L_0x0496:
            r0 = "  ";
            r8.append(r0);
            r4 = r4 + 1;
            r6 = r17;
            r7 = r18;
            goto L_0x043f;
        L_0x04a2:
            r17 = r6;
            r18 = r7;
            r0 = 0;
            r6 = 0;
        L_0x04a8:
            if (r0 != 0) goto L_0x04b2;
        L_0x04aa:
            r4 = r8.toString();
            r13.c = r4;
            goto L_0x03fb;
        L_0x04b2:
            r13.d = r6;
            r11 = 0;
            r13.b = r11;
            goto L_0x03fc;
        L_0x04b9:
            r16 = r4;
            r17 = r6;
            r18 = r7;
            r11 = 0;
            r4 = 0;
        L_0x04c1:
            if (r4 == 0) goto L_0x04d8;
        L_0x04c3:
            r0 = r5.Y();
            r6 = new org.json.JSONObject;
            r6.<init>();
            r13.b(r6);
            r6 = r6.toString();
            r7 = "anti_hijack_attempt";
            r0.putString(r7, r6);
        L_0x04d8:
            r0 = c.j.a.d.a.g.a;
            if (r0 == 0) goto L_0x0533;
        L_0x04dc:
            r0 = (c.j.a.c.g) r0;
            r0 = r5.g0();
            r0 = c.j.a.d.b.l.a.d(r0);
            r6 = "anti_hijack_report_config";
            r0 = r0.l(r6);
            if (r0 == 0) goto L_0x0533;
        L_0x04ee:
            r0 = c.j.a.c.g$g.d.c.a;
            r6 = r0.b(r5);
            if (r6 != 0) goto L_0x04f7;
        L_0x04f6:
            goto L_0x0533;
        L_0x04f7:
            r7 = new org.json.JSONObject;
            r7.<init>();
            r13.b(r7);
            r0 = "download_id";
            r8 = r5.g0();	 Catch:{ all -> 0x0517 }
            r7.put(r0, r8);	 Catch:{ all -> 0x0517 }
            r0 = "name";
            r8 = r5.b;	 Catch:{ all -> 0x0517 }
            r7.put(r0, r8);	 Catch:{ all -> 0x0517 }
            r0 = "url";
            r8 = r5.d;	 Catch:{ all -> 0x0517 }
            r7.put(r0, r8);	 Catch:{ all -> 0x0517 }
            goto L_0x051b;
        L_0x0517:
            r0 = move-exception;
            r0.printStackTrace();
        L_0x051b:
            r0 = r5.g0();
            c.j.a.c.g.y.f(r7, r0);
            r0 = c.j.a.c.o.b.b.a;
            r8 = "embeded_ad";
            r12 = "anti_hijack_result";
            r0.q(r8, r12, r7, r6);
            goto L_0x0533;
        L_0x052c:
            r16 = r4;
            r17 = r6;
            r18 = r7;
            r4 = 0;
        L_0x0533:
            if (r4 == 0) goto L_0x053d;
        L_0x0535:
            r11 = 1;
            goto L_0x0548;
        L_0x0537:
            r16 = r4;
            r17 = r6;
            r18 = r7;
        L_0x053d:
            r10 = r10 + 1;
            r4 = r16;
            r6 = r17;
            r7 = r18;
            r8 = 2;
            goto L_0x02dc;
        L_0x0548:
            if (r11 == 0) goto L_0x054c;
        L_0x054a:
            goto L_0x0218;
        L_0x054c:
            r10 = c.j.a.d.a.h.d(r2, r3);
        L_0x0550:
            r0 = r1.d;
            r2 = r1.c;
            c.j.a.d.a.h.m(r0, r2, r10);
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.a.h$a.run():void");
        }
    }

    /* compiled from: AbsAppDownloadDepend */
    public class b {
        public f a(Context context) {
            throw null;
        }

        public boolean b() {
            throw null;
        }
    }

    /* compiled from: IAppDownloadMonitorListener */
    public interface d {
        void a(com.ss.android.socialbase.downloader.g.c cVar, com.ss.android.socialbase.downloader.e.a aVar, int i);
    }

    /* compiled from: IDownloadAlertDialog */
    public interface e {
        void a();

        boolean b();
    }

    /* compiled from: IDownloadAlertDialogBuilder */
    public interface f {
        e a();

        f a(int i);

        f a(OnCancelListener onCancelListener);

        f a(String str);

        f a(boolean z);

        f b(int i, OnClickListener onClickListener);

        f c(int i, OnClickListener onClickListener);
    }

    /* compiled from: IInstallGuideEndCallback */
    public interface g {
    }

    /* compiled from: AbsDownloadAlertDialogBuilder */
    public abstract class c implements f {
        public f a(boolean z) {
            return null;
        }
    }

    public static int a() {
        Objects.requireNonNull(i.j());
        c0 c0Var = c.j.a.d.b.l.a.e;
        int i = 1;
        if (c.j.a.d.b.e.b.C().optInt("package_flag_config", 1) != 1) {
            i = 0;
        }
        return i != 0 ? 16384 : 0;
    }

    public static int b(int i) {
        if (i == 0) {
            return 0;
        }
        if (i == -2) {
            return 2;
        }
        int i2 = 1;
        if (i == 1) {
            return 4;
        }
        if (i.x(i) || i == 11) {
            return 1;
        }
        if (i >= 0 || i == -2 || i == -5) {
            i2 = 0;
        }
        return i2 != 0 ? 3 : 0;
    }

    public static int c(Context context, int i, boolean z) {
        int i2 = 0;
        if (c.j.a.d.b.l.a.d(i).b("install_queue_enable", 0) == 1) {
            i2 = 1;
        }
        if (i2 != 0) {
            return c.j.a.d.a.n.d.a.a(context, i, z);
        }
        return k(context, i, z);
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0016 */
    /* JADX WARNING: Failed to process nested try/catch */
    public static int d(android.content.Context r2, android.content.Intent r3) {
        /*
        r0 = 1;
        r1 = c.j.a.d.a.i.j();	 Catch:{ all -> 0x0016 }
        r1 = r1.i;	 Catch:{ all -> 0x0016 }
        if (r1 == 0) goto L_0x0016;
    L_0x0009:
        r1 = c.j.a.d.a.i.j();	 Catch:{ all -> 0x0016 }
        r1 = r1.i;	 Catch:{ all -> 0x0016 }
        r1 = r1.a(r3);	 Catch:{ all -> 0x0016 }
        if (r1 == 0) goto L_0x0016;
    L_0x0015:
        return r0;
    L_0x0016:
        r2.startActivity(r3);	 Catch:{ all -> 0x001a }
        return r0;
    L_0x001a:
        r2 = 0;
        return r2;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.a.h.d(android.content.Context, android.content.Intent):int");
    }

    public static PackageInfo e(Context context, String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return null;
        }
        File file = new File(str, str2);
        if (!file.exists()) {
            return null;
        }
        StringBuilder g = c.b.a.a.a.g("isApkInstalled apkFileSize：fileName:");
        g.append(file.getPath());
        g.append(" apkFileSize");
        g.append(file.length());
        Log.e("AppDownloadUtils", g.toString());
        return i.c(context, file, a());
    }

    public static String f(long j) {
        long[] jArr = new long[]{1099511627776L, 1073741824, 1048576, 1024, 1};
        String[] strArr = new String[]{"TB", "GB", "MB", "KB", "B"};
        if (j < 1) {
            StringBuilder g = c.b.a.a.a.g("0 ");
            g.append(strArr[4]);
            return g.toString();
        }
        String str = null;
        for (int i = 0; i < 5; i++) {
            long j2 = jArr[i];
            if (j >= j2) {
                String str2 = strArr[i];
                double d = (double) j;
                if (j2 > 1) {
                    d /= (double) j2;
                }
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(new DecimalFormat("#.##").format(d));
                stringBuilder.append(" ");
                stringBuilder.append(str2);
                str = stringBuilder.toString();
                return str;
            }
        }
        return str;
    }

    /* JADX WARNING: Removed duplicated region for block: B:19:0x0040  */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x0040  */
    /* JADX WARNING: Missing block: B:14:0x0034, code skipped:
            if (android.text.TextUtils.isEmpty(r2) == false) goto L_0x003a;
     */
    public static java.lang.String g(java.lang.String r1, java.lang.String r2, java.lang.String r3, boolean r4) {
        /*
        r0 = android.text.TextUtils.isEmpty(r1);
        if (r0 == 0) goto L_0x0009;
    L_0x0006:
        r1 = "";
        return r1;
    L_0x0009:
        r1 = android.net.Uri.parse(r1);
        r0 = "default.apk";
        if (r4 == 0) goto L_0x0026;
    L_0x0011:
        r4 = android.text.TextUtils.isEmpty(r2);
        if (r4 == 0) goto L_0x003a;
    L_0x0017:
        r2 = r1.getLastPathSegment();
        r2 = android.text.TextUtils.isEmpty(r2);
        if (r2 != 0) goto L_0x0037;
    L_0x0021:
        r2 = r1.getLastPathSegment();
        goto L_0x003a;
    L_0x0026:
        r1 = r1.getLastPathSegment();
        r4 = android.text.TextUtils.isEmpty(r1);
        if (r4 == 0) goto L_0x0039;
    L_0x0030:
        r1 = android.text.TextUtils.isEmpty(r2);
        if (r1 != 0) goto L_0x0037;
    L_0x0036:
        goto L_0x003a;
    L_0x0037:
        r2 = r0;
        goto L_0x003a;
    L_0x0039:
        r2 = r1;
    L_0x003a:
        r1 = p(r3);
        if (r1 == 0) goto L_0x004c;
    L_0x0040:
        r1 = ".apk";
        r3 = r2.endsWith(r1);
        if (r3 != 0) goto L_0x004c;
    L_0x0048:
        r2 = c.b.a.a.a.D(r2, r1);
    L_0x004c:
        return r2;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.a.h.g(java.lang.String, java.lang.String, java.lang.String, boolean):java.lang.String");
    }

    /* JADX WARNING: Missing block: B:19:0x0059, code skipped:
            if (null == null) goto L_0x005c;
     */
    public static boolean h(android.content.Context r9) {
        /*
        r0 = "android";
        r1 = 0;
        if (r9 != 0) goto L_0x0006;
    L_0x0005:
        return r1;
    L_0x0006:
        r2 = 0;
        r3 = "appdownloader_notification_title_color";
        r3 = c.j.a.c.y.a.i.A(r3);	 Catch:{ all -> 0x0059 }
        r4 = r9.getResources();	 Catch:{ all -> 0x0059 }
        r3 = r4.getColor(r3);	 Catch:{ all -> 0x0059 }
        r4 = "textColor";
        r4 = c.j.a.c.y.a.i.u(r4, r0);	 Catch:{ all -> 0x0059 }
        r5 = "textSize";
        r0 = c.j.a.c.y.a.i.u(r5, r0);	 Catch:{ all -> 0x0059 }
        r5 = 2;
        r5 = new int[r5];	 Catch:{ all -> 0x0059 }
        r5[r1] = r4;	 Catch:{ all -> 0x0059 }
        r4 = 1;
        r5[r4] = r0;	 Catch:{ all -> 0x0059 }
        r0 = "appdownloader_style_notification_title";
        r6 = c.j.a.d.b.e.b.a();	 Catch:{ Exception -> 0x0042 }
        r6 = r6.getResources();	 Catch:{ Exception -> 0x0042 }
        r7 = "style";
        r8 = c.j.a.d.b.e.b.a();	 Catch:{ Exception -> 0x0042 }
        r8 = r8.getPackageName();	 Catch:{ Exception -> 0x0042 }
        r0 = r6.getIdentifier(r0, r7, r8);	 Catch:{ Exception -> 0x0042 }
        goto L_0x0047;
    L_0x0042:
        r0 = move-exception;
        r0.printStackTrace();	 Catch:{ all -> 0x0059 }
        r0 = 0;
    L_0x0047:
        r2 = r9.obtainStyledAttributes(r0, r5);	 Catch:{ all -> 0x0059 }
        r9 = r2.getColor(r1, r1);	 Catch:{ all -> 0x0059 }
        if (r3 != r9) goto L_0x0055;
    L_0x0051:
        r2.recycle();	 Catch:{ all -> 0x0054 }
    L_0x0054:
        return r4;
    L_0x0055:
        r2.recycle();	 Catch:{ all -> 0x005c }
        goto L_0x005c;
    L_0x0059:
        if (r2 == 0) goto L_0x005c;
    L_0x005b:
        goto L_0x0055;
    L_0x005c:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.a.h.h(android.content.Context):boolean");
    }

    public static boolean i(Context context, com.ss.android.socialbase.downloader.g.c cVar) {
        String str = cVar.w;
        int i = cVar.t0;
        boolean z = false;
        if (i > 0) {
            PackageInfo packageInfo = null;
            try {
                packageInfo = context.getPackageManager().getPackageInfo(str, a());
            } catch (NameNotFoundException unused) {
            }
            if (packageInfo == null) {
                return false;
            }
            if (packageInfo.versionCode >= i) {
                z = true;
            }
            return z;
        }
        if (!(context == null || TextUtils.isEmpty(cVar.e) || TextUtils.isEmpty(cVar.b))) {
            z = n(context, cVar, e(context, cVar.e, cVar.b));
        }
        return z;
    }

    public static boolean j(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            if (new JSONObject(str).optBoolean("bind_app", false)) {
                return true;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static int k(Context context, int i, boolean z) {
        com.ss.android.socialbase.downloader.g.c k = c.j.a.d.b.e.i.a(context).k(i);
        if (k != null) {
            if (!(!"application/vnd.android.package-archive".equals(k.u) || TextUtils.isEmpty(k.e) || TextUtils.isEmpty(k.b))) {
                File file = new File(k.e, k.b);
                if (file.exists()) {
                    a aVar = new a(context, i, z, k, file);
                    context = c.j.a.d.b.e.b.a;
                    c.j.a.d.b.e.b.r().execute(aVar);
                    return 1;
                }
            }
        }
        m(k, z, 2);
        return 2;
    }

    public static String l() {
        Context a = c.j.a.d.b.e.b.a();
        File i = i.j().i();
        if (!(i != null && i.exists() && i.isDirectory())) {
            Object externalStorageState;
            File externalStoragePublicDirectory;
            a = a.getApplicationContext();
            try {
                externalStorageState = Environment.getExternalStorageState();
            } catch (IncompatibleClassChangeError | NullPointerException unused) {
                externalStorageState = "";
            }
            if ("mounted".equals(externalStorageState)) {
                externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            } else {
                externalStoragePublicDirectory = a.getFilesDir();
            }
            i = externalStoragePublicDirectory;
        }
        if (i != null) {
            StringBuilder stringBuilder;
            if (i.exists()) {
                if (!i.isDirectory()) {
                    stringBuilder = new StringBuilder();
                    stringBuilder.append(i.getAbsolutePath());
                    stringBuilder.append(" already exists and is not a directory");
                    throw new IllegalStateException(stringBuilder.toString());
                }
            } else if (!i.mkdirs()) {
                stringBuilder = c.b.a.a.a.g("Unable to create directory: ");
                stringBuilder.append(i.getAbsolutePath());
                throw new IllegalStateException(stringBuilder.toString());
            }
            return i.getAbsolutePath();
        }
        throw new IllegalStateException("Failed to get storage directory");
    }

    public static void m(com.ss.android.socialbase.downloader.g.c cVar, boolean z, int i) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("by_user", z ? 1 : 2);
            jSONObject.put("view_result", i);
            jSONObject.put("real_package_name", cVar.x);
        } catch (Exception e) {
            e.printStackTrace();
        }
        l lVar = c.j.a.d.b.e.b.Q;
        if (lVar != null) {
            lVar.a(cVar, "install_view_result", jSONObject);
        }
    }

    public static boolean n(Context context, com.ss.android.socialbase.downloader.g.c cVar, PackageInfo packageInfo) {
        if (packageInfo != null) {
            PackageInfo packageInfo2;
            String str = packageInfo.packageName;
            int i = packageInfo.versionCode;
            if (cVar != null) {
                cVar.t0 = i;
            }
            try {
                packageInfo2 = context.getPackageManager().getPackageInfo(str, a());
            } catch (NameNotFoundException unused) {
                packageInfo2 = null;
            }
            if (packageInfo2 != null) {
                int i2 = packageInfo2.versionCode;
                if (cVar == null || c.j.a.d.b.l.a.d(cVar.g0()).b("install_with_same_version_code", 0) != 1) {
                    if (i <= i2) {
                        return true;
                    }
                } else if (i < i2) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean o(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            if (new JSONObject(str).optBoolean("auto_install_without_notification", false)) {
                return true;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean p(String str) {
        return !TextUtils.isEmpty(str) && str.equals("application/vnd.android.package-archive");
    }
}
